package com.app.service.impl;

import com.app.common.CalculateDistance;
import com.app.mapper.BusinessMapper;
import com.app.mapper.UserBusinessMapper;
import com.app.model.BusinessModel;
import com.app.model.UserBusinessModel;
import com.app.service.CommentService;
import com.app.service.UserBusinessService;
import com.app.vo.BusinessVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户商家关联(收藏)
 *
 * @author 16693103420
 * @since 2024-01-23
 */
@Service
public class UserBusinessServiceImpl extends ServiceImpl<UserBusinessMapper, UserBusinessModel> implements UserBusinessService {

    @Autowired
    private UserBusinessMapper userBusinessMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private CommentService commentService;
    @Override
    public BusinessVo getUserBusiness(Integer page, Integer limit, Integer userId, Double longitude, Double latitude) {
        IPage<BusinessModel> businessModelIPage=new Page<>(page,limit);
        IPage<BusinessModel> businessList = businessMapper.getUserBusiness(businessModelIPage, userId, longitude, latitude);
        for (BusinessModel business : businessList.getRecords()) {
            business.setScore(commentService.getScore(business.getId()));
        }
        BusinessVo businessVo = new BusinessVo();
        businessVo.setList(businessList.getRecords());
        businessVo.setCount((int) businessList.getTotal());
        return businessVo;
    }
}
